﻿
//父控制器
app.controller("pageCtrl", function($scope) {

	
});

//登录--控制器
app.controller("loginCtrl", function($scope, $http,$rootScope) {
	$scope.name="";
	$scope.pwd="";
	$rootScope.page.topOpen=false;
	$rootScope.callSuccessHttp();
	
	$scope.login=function(){
		if($scope.name=="")
		{
			alert('请输入姓名')
		}
		else if($scope.pwd=="")
		{
			alert('请输入密码')
		}
		else
		{
			$rootScope.uiObj.layerloadingCtrl=true;
			var _link=buildUrl("json","settlement","login",{
				"loginName":$scope.name,
				"password":$scope.pwd
			})
			
			$http.get(_link).success(function(data){
				console.log(data);
				if(data.isbind)
				{
					location.reload();
				}
				else{
					alert(data.msg)
				}
				$rootScope.callSuccessHttp();
			})
		}
		
	}
	
});


//我的收入--控制器
app.controller("accountListCtrl", function($scope, $http,$rootScope,$routeParams) {
	
	$scope.page.topOpen=false;
	$scope.btype = $routeParams.type;
	$rootScope.callSuccessHttp();
	$scope.data={
		miCoins:balance,
		inM:totalRevenue,
		outT:price
	}
	var defaultstart=0,
		defaultlimit=10;
	$scope.pageUi={
		balancelist:[
			{
				start:defaultstart,
				limit:defaultlimit,
				iswork:true,
				tType:1,
				tabName:"收入",
				tabId:"tType0",
				menu:["时间","事由","金额"]
			},
			{
				start:defaultstart,
				limit:defaultlimit,
				iswork:true,
				tType:0,
				tabName:"结算",
				tabId:"tType1",
				menu:["时间","状态","金额"]
			}
			
		]
	}
	
	
});

//我要提现
app.controller('saveCashCtrl',function($scope,$rootScope,$routeParams,$http) {
	$rootScope.page.topOpen=true;
	$rootScope.page.title='结算申请';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
	$scope.cashsuccess=false;
	$scope.cashNum=null;
	$scope.data={
		miCoins:balance
	}
	$rootScope.callSuccessHttp();
	$scope.goindex=function(){
		var _link=buildUrl('html','settlement','index');
		window.location.href=_link;
	}
	$scope.saveCash=function(){
		var _link=buildUrl('json','settlement','saveCash',{
			id:document.getElementById('userid').value,
			agent:document.getElementById('agent').value,
			cash:$scope.cashNum
		})
		$scope.uiObj.layerloadingCtrl=true;
		if($scope.cashNum==null)
			{
				layer.open({
					content:'请输入结算金额'
				})
			}
		else
		{
			$http.get(_link).success(function(response){
				console.log(response);
				$scope.callSuccessHttp();
				if(response.code==0)
				{
					$scope.cashsuccess=true;
					$rootScope.page.topOpen=false;
				}
				else
				{
					layer.open({
						content:response.msg
					})
				}
				
			});
		}
	}
});
